
	$(function(){
        function listPageShow(provinceId,cityId,siteId,beginTime,endTime,keyWords,statusStr,pageNum){

            $.ajax({
                type:"post",
                url: WEBURL+"/capsummary/listall",
                'dataType':'json',
                'data':{
                    'provinceId':provinceId,
                    'cityId':cityId,
                    'siteId':siteId,
                    'beginTime':beginTime,
                    'endTime':endTime,
                    'keyWords':keyWords,
                    'statusStr':statusStr,
                    'pageNo':pageNum,
                    'pageSize':10

                },
                success:function(r){
                    var info = '';
                    if(r.code==0000){
                        $("#kkpager").html('');
                        $("#zdyl-listall").html('');
                        // console.log(r.data.dataList.length>0)
                        if(r.data.dataList.length>0){

                            $.each(r.data.dataList,function(index,item){


                                info=info+'<tr class="text-c">'+
                                    '<td>'+item.provinceName+'</td>'+
                                    '<td>'+item.cityName+'</td>'+
                                    '<td>'+item.siteName+'</td>'+
                                    '<td>'+item.orderTotalNum+'</td>'+
                                    '<td>'+item.orderEfficiencyNum+'</td>'+
                                    '<td>'+item.workerNum+'</td>'+
                                    '<td>'+item.siteEfficiency+'</td>'+
                                    '<td>'+item.siteDate+'</td><td>';
                                if(item.status==0){
                                    info = info+'<span class="btn btn btn-danger radius mr-10">已提交</span>';
                                }
                                else if(item.status==1){

                                    info = info+'<span class="btn btn-warning radius mr-10">已修改</span>';
                                }
                                else if(item.status==2){

                                    info = info+'<span class="btn btn-success radius mr-10">已审核</span>';
                                }


                                info = info+'<span onClick="system_category_add(\'查看\',\'zdyl-repair.html?id='+item.siteId+'&day='+item.siteDate+'&dataId='+item.id+'\',1100,600)" title="查看" class="btn btn-secondary radius">查看</span></td></tr>';

                            })


                        }
                        else{
                            info ='<tr class="text-c"><td colspan="10">暂无数据</td></tr>';
                        }
                        $(info).appendTo($("#zdyl-listall"));

                    }
                    //生成分页
                    var totaldata = r.data.totalRecord;
                    var totalpages = Math.floor((totaldata-1)/10)+1;

                    var totalPage = totaldata;
                    var pages =  totalpages;
                    //console.log(pages);
                    var totalRecords = totaldata;
                    var pageNo = localStorage.nn;

                    if(!pageNo) {
                        pageNo = 0;
                    }
                    //有些参数是可选的，比如lang，若不传有默认值
                    kkpager.generPageHtml({
                        pno: pageNo,
                        //总页码
                        total: totalpages,
                        //总数据条数
                        totalRecords: totaldata,
                        mode: 'click', //默认值是link，可选link或者click
                        click: function(n) {
                            var zdyl_provinceList =$("#provinceList").find("option:selected").attr("data-orgCode");
                            var zdyl_cityCompany =$("#cityList").find("option:selected").attr("data-orgCode");
                            var zdyl_siteId =$("#siteList").find("option:selected").attr("data-orgCode");
                            var zdyl_beginTime =$("#starttime").val();
                            var zdyl_endTime =$("#endtime").val();
                            var zdyl_keyWords =$("#zdyl-keyWords").val();
                            var zdyl_flag =$(".cityAreaShow").attr('data-status');


                            // do something
                            //手动选中按钮
                            this.selectPage(n);
                            localStorage.nn = n;

                            //pagelist(localStorage.nn);
                            listPageShow(zdyl_provinceList,zdyl_cityCompany,zdyl_siteId,zdyl_beginTime,zdyl_endTime,zdyl_keyWords,zdyl_flag,(localStorage.nn-1))
                            return false;
                        }

                    },true);
                }

            });

        }
		//查询数据列表
        localStorage.nn=0;
		function listShow(provinceId,cityId,siteId,beginTime,endTime,keyWords,statusStr,pageNum){
            localStorage.nn =pageNum;
            console.log(pageNum);

			$.ajax({
				type:"post",
				url: WEBURL+"/capsummary/listall",
				'dataType':'json',
				'data':{
					'provinceId':provinceId,
				    'cityId':cityId,
					'siteId':siteId,
                	'beginTime':beginTime,
					'endTime':endTime,
					'keyWords':keyWords,
					'statusStr':statusStr,
					'pageNo':pageNum,
					'pageSize':10

				},
				success:function(r){
					var info = '';
					if(r.code==0000){
                        $("#zdyl-listall").html('');
                       // console.log(r.data.dataList.length>0)
						if(r.data.dataList.length>0){

							 $.each(r.data.dataList,function(index,item){
							 	info=info+'<tr class="text-c">'+
											'<td>'+item.provinceName+'</td>'+
											'<td>'+item.cityName+'</td>'+
											'<td>'+item.siteName+'</td>'+
											'<td>'+item.orderTotalNum+'</td>'+
											'<td>'+item.orderEfficiencyNum+'</td>'+
											'<td>'+item.workerNum+'</td>'+
                                    		'<td>'+item.siteEfficiency+'</td>'+
											'<td>'+item.siteDate+'</td><td>';
								if(item.status==0){
									info = info+'<span class="btn btn btn-danger radius mr-10">已提交</span>';
								}
								else if(item.status==1){
									
									info = info+'<span class="btn btn-warning radius mr-10">已修改</span>';
								}
								else if(item.status==2){
									
									info = info+'<span class="btn btn-success radius mr-10">已审核</span>';
								}
								
								
								info = info+'<span onClick="system_category_add(\'查看\',\'zdyl-repair.html?id='+item.siteId+'&day='+item.siteDate+'&dataId='+item.id+'\',1100,600)" title="查看" class="btn btn-secondary radius">查看</span></td></tr>';
							 	
							 })
							
							  
						}
						else{
							info ='<tr class="text-c"><td colspan="10">暂无数据</td></tr>';
						}
						$(info).appendTo($("#zdyl-listall"));

					}
					$("#kkpager").html('');
                    //生成分页
                   var totaldata = r.data.totalRecord;
                   var totalpages = Math.floor((totaldata-1)/10)+1;

                    var totalPage = totaldata;
                    var pages =  totalpages;
                    //console.log(pages);
                    var totalRecords = totaldata;
                    var pageNo = localStorage.nn;

                    if(!pageNo) {
                        pageNo = 0;
                    }
                    //有些参数是可选的，比如lang，若不传有默认值
                    kkpager.generPageHtml({
                        pno: pageNo,
                        //总页码
                        total: totalpages,
                        //总数据条数
                        totalRecords: totaldata,
                        mode: 'click', //默认值是link，可选link或者click
                        click: function(n) {
                            var zdyl_provinceList =$("#provinceList").find("option:selected").attr("data-orgCode");
                            var zdyl_cityCompany =$("#cityList").find("option:selected").attr("data-orgCode");
                            var zdyl_siteId =$("#siteList").find("option:selected").attr("data-orgCode");
                            var zdyl_beginTime =$("#starttime").val();
                            var zdyl_endTime =$("#endtime").val();
                            var zdyl_keyWords =$("#zdyl-keyWords").val();
                            var zdyl_flag =$(".cityAreaShow").attr('data-status');


                            // do something
                            //手动选中按钮
                            this.selectPage(n);
                            localStorage.nn = n;

                            //pagelist(localStorage.nn);
                            listPageShow(zdyl_provinceList,zdyl_cityCompany,zdyl_siteId,zdyl_beginTime,zdyl_endTime,zdyl_keyWords,zdyl_flag,(localStorage.nn-1))
                            return false;
                        }

                    },true);


                  localStorage.setItem("ZdylRepairTag"," ");
				}
				
			});
			
		}


		
		//listShow()


		//数据导出
		$(".zdyl-export").on("click",function(){
            if($("#starttime").val()==''){
                $.Huimodalalert('请选择时间！',2000);
                return false;
            };
            if($("#endtime").val()==''){
                $.Huimodalalert('请选择时间！',2000);
                return false;
            };

            var oFrm = document.getElementById('iframe');
            var timeLoad =   window.setTimeout(function(){
                $.Huimodalalert('数据下载中,请稍后。。。。',2000);
             },300);

                oFrm.onload = oFrm.onreadystatechange = function() {
                if (this.readyState && this.readyState != 'complete') return;
                else {
                    window.clearTimeout(timeLoad);
                   alert('未查询到数据！');
                }
            }
            var url =WEBURL +'/capsummary/exportall?provinceId='+$("#provinceList  option:selected").attr('data-orgcode')+'&cityId='+$("#cityList  option:selected").attr('data-orgcode')+'&siteId='+$("#siteList option:selected").attr('data-orgcode')+'&beginTime='+$("#starttime").val()+'&endTime='+$("#endtime").val()+'&keyWords='+$("#zdyl-keyWords").val()+'&statusStr='+$("#zdyl-flag").parent('.cityAreaShow').attr("data-status");
            $("#iframe").attr("src",url);




		})


        //模拟下拉框多选
        selectOptionAll(".selectOptionAll2");

		//点击查询
		$(".zdyl-search-btn").on("click",function(){

			var zdyl_provinceList =$("#provinceList").find("option:selected").attr("data-orgCode");
            var zdyl_cityCompany =$("#cityList").find("option:selected").attr("data-orgCode");
            var zdyl_siteId =$("#siteList").find("option:selected").attr("data-orgCode");
            var zdyl_beginTime =$("#starttime").val();
            var zdyl_endTime =$("#endtime").val();
            var zdyl_keyWords =$("#zdyl-keyWords").val();
            var zdyl_flag =$(".cityAreaShow").attr('data-status');

            if(zdyl_beginTime==""||zdyl_beginTime==undefined||zdyl_beginTime==null){
                $.Huimodalalert('请选择时间！',2000);
                return false;
            };
            if(zdyl_endTime==""||zdyl_endTime==undefined||zdyl_endTime==null){
                $.Huimodalalert('请选择时间！',2000);
                return false;
            }

            if(zdyl_beginTime>zdyl_endTime){
                $.Huimodalalert('结束时间不能小于开始时间,请重新选择！',2000);
                return;
			}
			var nn =0;
            if(localStorage.ZdylRepairTag=="1"){
                nn = localStorage.nn;
            };
            listShow(zdyl_provinceList,zdyl_cityCompany,zdyl_siteId,zdyl_beginTime,zdyl_endTime,zdyl_keyWords,zdyl_flag,nn)

        })


		//查询条件重置
		$(".zdyl-reset-btn").on("click",function(){
			$("#provinceList option").eq(0).prop("selected",'selected');
            $("#cityList option").eq(0).prop("selected",'selected');
            $("#siteList option").eq(0).prop("selected",'selected');
            $("#zdyl-keyWords").prop("disabled",false);
            $("#zdyl-keyWords").val('');
            $("#starttime").val('');
            $("#endtime").val('');
            $("#provinceList").prop('disabled',false);
            $("#cityList").prop('disabled',false);
            $("#siteList").prop('disabled',false);
            $("#cityAreaList em").removeClass('bgcheck');
            $("#zdyl-flag").val('请选择');
            $(".cityAreaShow").attr('data-status',' ');
		});

        $("#provinceList").change(function(){
			$("#zdyl-keyWords").prop('disabled','true');
		});
        $("#zdyl-keyWords").blur(function(){

        	if($(this).val()==''){
                $("#provinceList").prop('disabled',false);
                $("#cityList").prop('disabled',false);
                $("#siteList").prop('disabled',false);
			}
			else{
                $("#provinceList").prop('disabled','true');
                $("#cityList").prop('disabled','true');
                $("#siteList").prop('disabled','true');
			}

		})



		$("#starttime").focus(function(){

			$(".allSelect").hide();
		})


	})
	



